import 'dart:convert';

class CountryBean {
  String? code;
  String? name;
  List<CountryBean>? children;

  CountryBean({this.code, this.name, this.children});

  @override
  String toString() {
    return 'CountryBean(code: $code, name: $name, children: $children)';
  }

  factory CountryBean.fromCode11NameChildrenCode1101NameChildrenCode110101NameCode110102Name(
      Map<String, dynamic> data) {
    return CountryBean(
      code: data['code'] as String?,
      name: data['name'] as String?,
      children: (data['children'] as List<dynamic>?)
          ?.map((e) => CountryBean
              .fromCode11NameChildrenCode1101NameChildrenCode110101NameCode110102Name(
                  e as Map<String, dynamic>))
          .toList(),
    );
  }

  Map<String, dynamic>
      toCode11NameChildrenCode1101NameChildrenCode110101NameCode110102Name() {
    return {
      'code': code,
      'name': name,
      'children': children
          ?.map((e) => e
              .toCode11NameChildrenCode1101NameChildrenCode110101NameCode110102Name())
          .toList(),
    };
  }

  /// `dart:convert`
  ///
  /// Parses the string and returns the resulting Json object as [CountryBean].
  factory CountryBean.fromJson(String data) {
    return CountryBean
        .fromCode11NameChildrenCode1101NameChildrenCode110101NameCode110102Name(
            json.decode(data) as Map<String, dynamic>);
  }

  static List<CountryBean> fromJsonList(String data) {
    return (json.decode(data) as List<dynamic>)
        .map((e) => CountryBean
            .fromCode11NameChildrenCode1101NameChildrenCode110101NameCode110102Name(
                e))
        .toList();
  }

  /// `dart:convert`
  ///
  /// Converts [CountryBean] to a JSON string.
  String toJson() => json.encode(
      toCode11NameChildrenCode1101NameChildrenCode110101NameCode110102Name());
}
